package net.uhuijia.zb.userzhubolivefeedback.service.impl;

import net.uhuijia.appbase.redis.IRedisDao;
import net.uhuijia.zb.userzhubolivefeedback.service.UserZhuboLiveFeedBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import net.uhuijia.appbase.service.CrudService;
import net.uhuijia.zb.userzhubolivefeedback.persistence.dao.UserZhuboLiveFeedBackDao;
import net.uhuijia.zb.userzhubolivefeedback.persistence.model.UserZhuboLiveFeedBack;
import net.uhuijia.zb.userzhubolivefeedback.persistence.model.UserZhuboLiveFeedBackExample;


@Service
@Transactional
public class UserZhuboLiveFeedBackServiceImpl
     extends CrudService<UserZhuboLiveFeedBackDao,UserZhuboLiveFeedBack,UserZhuboLiveFeedBackExample> implements UserZhuboLiveFeedBackService {
    @Autowired
    private UserZhuboLiveFeedBackDao userZhuboLiveFeedBackDao;
    @Autowired
    private IRedisDao<String,Object> redisDao;

    /**
     * 初始化评价数据
     * @param liveId 当前直播Id
     * @param feedBackUserId 评论人
     * @param content 评论内容
     * @return
     */
    @Override
    public UserZhuboLiveFeedBack generalUserZhuboLiveFeedBack(String liveId, String feedBackUserId, String content) {
        UserZhuboLiveFeedBack userZhuboLiveFeedBack = new UserZhuboLiveFeedBack();
        userZhuboLiveFeedBack.setContent(content);
        userZhuboLiveFeedBack.setFeedBackUserId(feedBackUserId);
        userZhuboLiveFeedBack.setLiveId(liveId);
        return userZhuboLiveFeedBack;
    }

    /**
     * 添加用户评价
     * @param liveId
     * @param feedBackUserId
     * @param content
     * @return
     */
    @Override
    public UserZhuboLiveFeedBack addUserZhuboLiveFeedBack(String liveId, String feedBackUserId, String content) {
        UserZhuboLiveFeedBack userZhuboLiveFeedBack = this.generalUserZhuboLiveFeedBack(liveId,feedBackUserId,content);
        String result = this.add(userZhuboLiveFeedBack);
        if(SUCCESS.equals(result)){
            return userZhuboLiveFeedBack;
        }else
            return null;
    }
}